package com.liwang.lanouhn.nvshengo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.liwang.lanouhn.nvshengo.Info.CosmeticLiveInfo;
import com.liwang.lanouhn.nvshengo.Info.VideoInfo;
import com.liwang.lanouhn.nvshengo.R;
import com.liwang.lanouhn.nvshengo.activities.CosmeticLiveActivity;
import com.squareup.picasso.Picasso;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by lanouhn on 2016/10/14.
 */
public class CosmeticLiveAdapter extends RecyclerView.Adapter<CosmeticLiveAdapter.CosmeticliveViewHolder> {
    private Context context;
    private CosmeticLiveInfo cosmeticLiveInfo;



    public CosmeticLiveAdapter(Context context, CosmeticLiveInfo cosmeticLiveInfo) {
        this.context = context;
        this.cosmeticLiveInfo = cosmeticLiveInfo;
    }

    @Override
    public CosmeticliveViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_cosmeticlive,null);
        CosmeticliveViewHolder holder = new CosmeticliveViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(CosmeticliveViewHolder holder, final int position) {
        final CosmeticLiveInfo.DataBean.ItemsBean bean =cosmeticLiveInfo.getData().getItems().get(position);
        Picasso.with(context).load(bean.getPreview()).into(holder.iv_background);
        holder.tv_title.setText(bean.getChannel().getStatus());
        holder.tv_view.setText(bean.getViewers()+"");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                VideoInfo videoInfo =new VideoInfo();
                videoInfo.setId(bean.getChannel().getId());
                videoInfo.setDomain(bean.getChannel().getDomain());
                videoInfo.setUrl(bean.getPreview());
                videoInfo.setRoomname(bean.getChannel().getStatus());
                videoInfo.setViewer(bean.getViewers()+"");
                Intent intent =new Intent(context, CosmeticLiveActivity.class);
                intent.putExtra("videoInfo",videoInfo);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return cosmeticLiveInfo.getData().getItems().size();
    }

    public class CosmeticliveViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_background;
        private TextView  tv_name, tv_view,tv_title;
        private CircleImageView iv_head;

        public CosmeticliveViewHolder(View itemView) {
            super(itemView);
            iv_background = (ImageView) itemView.findViewById(R.id.iv_back);
            iv_head = (CircleImageView) itemView.findViewById(R.id.iv_head);
            tv_name= (TextView) itemView.findViewById(R.id.tv_name);
            tv_view= (TextView) itemView.findViewById(R.id.tv_view);
            tv_title= (TextView) itemView.findViewById(R.id.tv_title);

        }
    }
}
